package com.iqiyi.pps.epg.core.service.auth;

import com.iqiyi.pps.epg.core.dao.auth.ResourceDao;
import com.iqiyi.pps.epg.core.dao.base.Page;
import com.iqiyi.pps.epg.core.dao.base.PropertyFilter;
import com.iqiyi.pps.epg.core.model.auth.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class ResourceManager{
	@Autowired
	private ResourceDao resourceDao;

	// Resource Manager //
	
	/* Get one */
	@Transactional(readOnly = true)
	public Resource getResource(Long id) {
		return resourceDao.get(id);
	}
	
	/* Get All */
	public List<Resource> getAllResource() {
		List<Resource> resourceList = resourceDao.getAll();
		return resourceList;
	}
	
	/* Save one */
	public void saveResource(Resource resource) {
		resourceDao.save(resource);
	}

    /* Delete one */
	public void deleteResource(Long id) {
		resourceDao.delete(id);
	}
	
	/* Search */
	 @Transactional(readOnly = true)
     public Page<Resource> searchResource(final Page<Resource> page, final List<PropertyFilter> filters){
          return resourceDao.findPage(page, filters);
      }

    @Transactional(readOnly = true)
	public boolean isResourceNameUnique(String newResourceName, String oldResourceName) {
		return resourceDao.isPropertyUnique("name", newResourceName, oldResourceName);
	}
	
}

